package com.gack.business.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.gack.business.model.StoreSupportFacity;

/**
 * 
* @ClassName: StoreSupportFacityRepository 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author (ZhangXinYu)  
* @date 2018年6月4日 上午11:25:38 
* @version V1.0
 */
public interface StoreSupportFacityRepository extends JpaRepository<StoreSupportFacity, String>{
	public List<StoreSupportFacity> findByName(String facityName);
	
	//删除门店配套设施
	@Transactional
	@Modifying
	@Query("delete from StoreSupportFacity where id = :id and isUse = 0")
	public Integer dealStoreSupportFacity(@Param("id") String id);
	
	//查询指定id的门店配套设施
	@Query("select f from StoreSupportFacity f where f.id in (:ids)")
	public List<StoreSupportFacity> getFacityByIds(@Param("ids") List<String> ids);
	
	//查询名称重复次数
	@Query("select count(f.id) from StoreSupportFacity f where f.name = :name")
	public Integer getCountOfSameName(@Param("name")String name); 
	
	//被删除的门店配套设施
	@Query("select f from StoreSupportFacity f"
			+ " where 1 = 1 and f.isUse = 0 and f.name not in (:facityNames)")
	public List<StoreSupportFacity> getBeDealStoreSupportFacity(@Param("facityNames")List<String> facityNames);
	
	//删除不存在的门店配套设施
	@Transactional
	@Modifying
	@Query("delete from StoreSupportFacity f "
			+ " where 1 = 1 and f.isUse = 0 and f.name not in (:facityNames) ")
	public int dealNotExistsStoreSupportFacity(@Param("facityNames")List<String> facityNames);
	
	//查询所有门店配套设施名称
	@Query("select f.name from StoreSupportFacity f")
	public List<String> getAllStoreSupportFacityNames();
}
